######################################################
#
# Markdown make file.
# It can convert xxx.md to xxx.html and xxx.pdf
#
# Wroten by: Hevake Lee
# E-mail: hevake_lcj@126.com
#
######################################################

MD = markdown
MDFLAGS =
RM = rm -f
ECHO = echo

markdown_files = $(wildcard *.md)
html_files = $(patsubst %.md,%.html,$(markdown_files))
pdf_files = $(patsubst %.md,%.pdf,$(markdown_files))
title = $(subst .md,,$(markdown_files))

all : html pdf

html : $(html_files)

$(html_files) : %.html : %.md
	@$(ECHO) '<html><head>' > $@
	@$(ECHO) "<title>工作笔记</title>" >> $@
	@$(ECHO) '<meta charset="utf-8"/>' >> $@
	@$(ECHO) '</head>' >> $@
	@$(ECHO) '<body>' >> $@
	@$(MD) $(MDFLAGS) $^ >> $@
	@$(ECHO) '</body></html>' >> $@
	@$(ECHO) 'HTML is built.'

pdf : 
	@echo "PDF is undo."

.PHONY : clean all

clean :
	-$(RM) $(html_files) $(pdf_files)

test:
	@echo $(markdown_files)
	@echo $(html_files)
